﻿; $(function () {
    $("#toolbar").ligerToolBar({
        items: [{
            text: '添加',
            icon: '',
            id: 'btnSave',
            click: function (parameters) {
                location.href = "/EZine/EZine";
            }
        },
            {
                text: '编辑',
                icon: '',
                id: 'btnEdit',
                click: function (parameters) {
                    var rows = manager.getSelectedRows();
                    if (rows && rows.length == 1) {
                        var row = manager.getSelectedRow();
                        if (row && row.Id != "") {
                            //if (row.IsChecked == 1) {
                            //} else {
                            location.href = "/EZine/EZine?Id=" + row.Id;
                            // }
                        } else {
                            $.ligerDialog.warn('请选择单条记录');
                        }
                    } else {
                        $.ligerDialog.warn('请选择单条记录');
                    }
                }
            },
            {
                text: '删除',
                icon: '',
                id: 'btnDelete',
                click: function (parameters) {

                    var rows = manager.getSelectedRows();
                    if (rows && rows.length > 0) {
                        if (confirm("确认删除？")) {
                            var ids = new Array();
                            $.each(rows, function () {
                                ids.push(this.Id);
                            });
                            $.ajax({
                                url: '/EZine/DeleteDocs',
                                dataType: 'json',
                                type: 'post',
                                data: { ids: ids.join(",") },
                                traditional: true,
                                success: function (callback) {
                                    if (callback) {
                                        $.ligerDialog.alert('删除成功', function (yes) {
                                            manager.loadData();
                                        });
                                    }
                                    else {
                                        $.ligerDialog.error('删除失败');
                                    }
                                },
                                error: function (ex) {
                                    $.ligerDialog.error('删除失败');
                                }
                            });
                        }

                    } else {

                    }


                }
            }]
    });


    var manager = $("#grid").ligerGrid({
        columns: [
            //{
            //    display: '序号',
            //    align: 'center',
            //    width: 50,
            //    minWidth: 50,
            //    render: function (item, i) {
            //        return (i + 1).toString();
            //    }
            //},
            { display: 'ID', name: 'UserID', isSort: false, width: 40, align: 'left', hide: true },
            {
                display: '登录名',
                align: 'left',
                width: 100,
                minWidth: 100,
                name: 'LoginName'
                //,
                //render: function (item, i, value) {
                //    return "<a href='/EZine/EZine?Id=" + item.Id + "'>" + item.Title + "</a>";
                //}
            },
            {
                display: '企业名称',
                align: 'left',
                width: 200,
                minWidth: 100,
                name: 'CompanyName',
                render: function (item, i, value) {
                    return item.Company.Name;
                }
            },
            {
                display: '企业联系电话',
                align: 'center',
                width: 120,
                minWidth: 100,
                name: 'CompanyName',
                render: function (item, i, value) {
                    return item.Company.Phone;
                }
            },
            { display: '注册时间', name: 'RegDate', isSort: false, width: 100, align: 'center', type: 'date' },
            {
                display: '是否审核',
                align: 'center',
                width: 80,
                minWidth: 60,
                name: 'IsCheck',
                render: function (item, i, value) {
                    return item.IsCheck == "0" ? "未审核" : "已审核";
                }
            },
            {
                display: '操作',
                align: 'center',
                width: 120,
                minWidth: 100,
                name: 'CompanyName',
                render: function (item, i, value) {
                    return item.IsCheck == "0" ? "<a class='btnPass' data-id='" + item.UserID + "' href='#'>通过</a>" :
                        "<a class='btnNoPass' data-id='" + item.UserID + "' href='#'>不通过</a>";
                }
            }
        ],
        width: '99.85%',
        height:
            '100%',
        heightDiff:
            -20,
        pageSizeOptions:
            [5, 10, 15, 20],
        pageSize: 15,
        //data: TreeDeptData,
        alternatingRow:
            false,
        url:
            "/User/Users",
        headerRowHeight:
            26,
        checkbox: true,
        autoCheckChildren: false,
        dataAction: "server",
        rowAttrRender:
            function (item, index) {
                return "";
            }
    }


);

    $(".btnPass").live("click",function (e) {
            if (confirm("确认通过审核？")) {
                var ids = new Array();
                //$.each(rows, function () {
                ids.push($(this).data("id"));
                //});
                $.ajax({
                    url: '/User/CheckUsers',
                    dataType: 'json',
                    type: 'post',
                    data: { ids: ids.join(","),state : 1 },
                    traditional: true,
                    success: function (callback) {
                        if (callback) {
                            $.ligerDialog.alert('操作成功', function (yes) {
                                manager.loadData();
                            });
                        }
                        else {
                            $.ligerDialog.error('操作失败');
                        }
                    },
                    error: function (ex) {
                        $.ligerDialog.error('操作失败');
                    }
                });
            }

    });

    $(".btnNoPass").live("click", function (e) {
        if (confirm("确认取消审核？")) {
            var ids = new Array();
            //$.each(rows, function () {
            ids.push($(this).data("id"));
            //});
            $.ajax({
                url: '/User/CheckUsers',
                dataType: 'json',
                type: 'post',
                data: { ids: ids.join(","), state: 0 },
                traditional: true,
                success: function (callback) {
                    if (callback) {
                        $.ligerDialog.alert('操作成功', function (yes) {
                            manager.loadData();
                        });
                    }
                    else {
                        $.ligerDialog.error('操作失败');
                    }
                },
                error: function (ex) {
                    $.ligerDialog.error('操作失败');
                }
            });
        }
    });

    $(".btnQuery").click(function () {
        manager.options.parms = [
            { name: 'cname', value: $("#cname").val() },
            { name: 'ischeck', value: $("#ischeck").is(":checked") }
        ];
        manager.options.newPage = 1;
        manager.loadData();
    });
});
